package sketch.doc;

import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;


public class Stroke {

	private List<Point> points;

	private int id;

	public Stroke() {
		init();
	}

	private void init() {
		points = new ArrayList<Point>();
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void appendPoint(Point p) {
		points.add(p);
	}

	public void draw(Graphics2D g2) {
		if (points.size() <= 1)
			return;

		Point p1 = points.get(0);
		for (int i = 1; i < points.size(); i++) {
			Point p2 = points.get(i);
			g2.drawLine((int) p1.x, (int) p1.y,
						(int) p2.x, (int) p2.y);
			p1 = p2;
		}
	}

	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("Stroke:");
		buf.append(getId());
		buf.append(":");
		for (Point point : points) {
			buf.append(point.toString());
		}
		return buf.toString();
	}

	public void drawLastPoint(Graphics2D g2) {
		int len = points.size();
		if (len <= 1)
			return;

		Point p1 = points.get(len - 2);
		Point p2 = points.get(len - 1);

		g2.drawLine((int) p1.x, (int) p1.y,
					(int) p2.x, (int) p2.y);

	}

}
